package com.example.grpc.consume.interceptor;

import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.ClientCall;
import io.grpc.ClientInterceptor;
import io.grpc.MethodDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author liyuncong
 * @version 1.0
 * @file LogGrpcInterceptor
 * @brief LogGrpcInterceptor
 * @details Grpc log 拦截器，打印请求参数
 * @date 2022-11-09
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                        NAME               DESCRIPTION
 * 2022-11-09                  liyuncong          Created
 */
public class LogGrpcInterceptor implements ClientInterceptor {

    private static final Logger logger = LoggerFactory.getLogger(LogGrpcInterceptor.class);

    @Override
    public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
        MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions, Channel channel) {
        logger.info(methodDescriptor.getBareMethodName());
        return channel.newCall(methodDescriptor, callOptions);
    }
}
